<?php

namespace App\Service\UserCenter\v1_3_5;

use App\Model\Stat\StatDailyHostInfo;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 视频通话排行榜
 */
class HostCallRankService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $type = $this->request->input('type', 'week');
        $ret['list'] = [];
        //周一
//        $mondayTs = (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600);
//        $sundayTs = (time() + (date('w') == 0 ? 0 : (7 - date('w'))) * 24 * 3600);
//        $monday = date('Y-m-d', $mondayTs);
//
//        $today = date('Y-m-d');
//
//        $rankList = StatDailyHostInfo::getCallRankList(10, $monday);
//        $userIds = array_column($rankList, 'user_id');
//        $userIds[] = $userId;
        $userProfiles = UserProfile::getUsersProfile($userIds, true);
//        $callMins = 0;
//        $reward = [5000, 2000, 1000];
//        $selfRank = 0;
//        foreach ($rankList as $k => $item) {
//            $uid = $item['user_id'];
//            $profile = $userProfiles[$uid];
//            $callMins = $item['call_minutes'];
//            // $extraTip = $today < '2022-04-11' ? '' : ($k >= 3 ? '' : "奖励{$reward[$k]}金币")
//            $extraTip = '';
//            $ret['list'][] = [
//                'user_id' => $uid,
//                'nick_name' => $profile['nick_name'],
//                'rank_text' => "通话{$callMins}分钟",
//                'avatar' => UserProfile::buildAvatar($profile['avatar'], 80),
//                'extra_tip' => $extraTip,
//            ];
//            if ($uid == $userId) $selfRank = $k + 1;
//        }
//
//        $myCallMins = StatDailyHostInfo::getCallData($userId, $monday);
        $selfProfile = $userProfiles[$userId];
//        $offCallMins = $callMins - $myCallMins;
        $ret['my_info'] = [
            'nick_name' => $selfProfile['nick_name'],
//            'rank_text' => "通话{$myCallMins}分钟",
            'rank_text' => "活动暂未开始",
            'avatar' => UserProfile::buildAvatar($selfProfile['avatar'], 80),
            'extra_tip' => "活动暂未开始",
//            'extra_tip' => $selfRank == 0 ? "还差{$offCallMins}分钟上榜" : "第{$selfRank}名",
        ];
//        $ret['my_info'] = [];

//        $showMonDate = date('Y/m/d', $mondayTs);
//        $showMonDate < '2022/12/12' && $showMonDate = '2022/12/12';
//        $showToday = date('m/d', $sundayTs);

//        $ret['time_range'] = "{$showMonDate}~{$showToday}"; //"{$showMonDate}~{$showToday}（数据从04/11正式统计奖励）";
        $ret['time_range'] = "2022/12/12~2022/12/12";
        $ret['rules'] = '活动暂未开始';
//                 $ret['rules'] = '1.每周一00:00～每周日23:59为一周期（数据从12月12日正式统计奖励）
//2.每周周星前10名可获得平台奖励，奖励于每周一发放至账户可提现;
//第1名：988元
//第2名：688元
//第3名：520元
//第4名～第10名：108元
//3.用户每周视频通话大于或者等于1000分钟后可获得奖励;
//4.活动最终解释权归平台所有';
        check_dev_env() && log_user_result($userId, $ret);
        return $ret;
    }
}
